//
//  OneImageTableViewCell.m
//  Wangi
//
//  Created by ChuXiang on 15/11/25.
//  Copyright © 2015年 ChuXiang. All rights reserved.
//

#import "OneImageTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+UIViewAdditions.h"
@interface OneImageTableViewCell ()
@property (nonatomic, retain) UIImageView *image;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *label;
@end
@implementation OneImageTableViewCell
- (void)dealloc {
    [_image release];
    [_titleLabel release];
    [_label release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.image];
        [self addSubview:self.titleLabel];
        [self addSubview:self.label];
        [_image release];
        [_titleLabel release];
        [_label release];
    }
    return self;
}
- (void)setModel:(BaseModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_image sd_setImageWithURL:[NSURL URLWithString:_model.imgsrc]];
    _titleLabel.text = _model.title;
    _label.text = _model.digest;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _titleLabel.frame = CGRectMake(5, 5, self.width - 30, 20);
    _image.frame = CGRectMake(5, _titleLabel.bottom + 5, self.width - 10, self.height - 60);
    _label.frame = CGRectMake(5, _image.bottom + 4, _image.width, 20);
}

#pragma mark - 懒加载
- (UIImageView *)image {
    if (!_image) {
        self.image = [[UIImageView alloc] initWithFrame:CGRectZero];
        [_image release];
    }
    return _image;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        [_titleLabel release];
    }
    return _titleLabel;
}

- (UILabel *)label {
    if (!_label) {
        self.label = [[UILabel alloc] initWithFrame:CGRectZero];
        _label.font = [UIFont systemFontOfSize:13];
        _label.textColor = [UIColor grayColor];
        [_label release];
    }
    return _label;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
